import java.util.Scanner;

public class demo6 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int q=scan.nextInt();
        for (int i = 0; i < q; i++) {
            int a2=scan.nextInt();
            int a3=scan.nextInt();
            int a4=scan.nextInt();

            int b4= scan.nextInt();
            int b6=scan.nextInt();
            int n=0;//记录满足要求的人数

            while(b6>0) {
                if(a2>=3) {
                    n+=6;
                    a2-=3;
                    b6-=1;
                }
                else if(a2>=1&&a4>=1) {
                    n+=6;
                    a2-=1;
                    a4-=1;
                    b6-=1;
                }
                else if(a3>=2){
                    n+=6;
                    a3-=2;
                }else {
                    break;
                }
            }
            while(b4>0) {
                if(a2>=2) {
                    n+=4;
                    a2-=2;
                    b4-=1;
                }
                else if(a4>=1) {
                    n+=4;
                    a4-=1;
                    b4-=1;
                }else {
                    break;
                }
            }

            System.out.println(n);
        }
    }
}
